// bsp6_3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string.h>
#include <stdlib.h>

bool isPalindrom(char*);

int _tmain(int argc, _TCHAR* argv[])
{
	long sum = 0;
	for(int i = 0; i <= 1000000; i++)
	{
		char *base10 = new char[7];
		char *base2 = new char[20];
		itoa(i, base10, 10);
		itoa(i, base2, 2);
		if(isPalindrom(base10))
		{
			if(isPalindrom(base2))
			{
				printf("%s (10) --- %s (2)\n", base10, base2);
				sum += i;
			}
		}
	}
	printf("Sum of all palindromic numbers = %ld", sum);
	getchar();
}

bool isPalindrom(char *text)
{
	for(int i = 0; i <= strlen(text)/2; i++)
	{
		if(text[i] != text[strlen(text)-1-i])
			return false;
	}
	return true;
}

